import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import store from '@/store'
Vue.use(VueRouter);
import Vuex from "../store/index.js";

console.log(Vuex)
const routes = [
  {
    path: "/",
    name: "home",
    component: HomeView,
  },
  {
    path: "/about",
    name: "about",
    component: () =>
      import("../views/AboutView.vue"),
  },
  {
    path: "/video",
    name: "video",
    component: () =>
      import("../views/VideoView.vue"),
  },
  {
    path: "/type",
    name: "type",
    component: () =>
      import("../views/TypeView.vue"),
  },{
    path:"/login",
    name:"login",
    component:() => import("../views/LoginView.vue")
  },
  {
    path: "/login",
    name: "login",
    component: () =>
      import("../views/LoginView.vue"),
  },
  {
    path: "/talk",
    name: "talk",
    component: () =>import("../views/TalkView.vue"),
    beforeEnter:(to,from,next)=>{
      console.log(to,from)
      let token = store.state.token
      if(token){
        console.log(token,"123123")
        next();
      }else{
        next({name:"login",params:{name:"talk"}});
      }
      
    }
  },
  {
    path: "/mine",
    name: "mine",
    component: () =>
    import("../views/MineView.vue"),
    beforeEnter:(to,from,next)=>{
      console.log(to,from)
      let token = store.state.token
      if(token){
        console.log(token)
        next();
      }else{
        next({name:"login",params:{name:"my"}});
      }
      
    }
}
];

const router = new VueRouter({
  routes,
});
// 权限管理

export default router;
